<?php
   //获取前面页面提交过来表单的数据
//    echo $_REQUEST['username'];
//    echo "<br/>";
//    echo $_REQUEST['message'];
//    echo "<br/>";
//    echo $_REQUEST['sex'];
//    echo "<br/>";
//    echo $_REQUEST['imgurl'];
//    echo "<img src='{$_REQUEST['imgurl']}'  />"
include 'dbcon.php';//连接数据库
//收集用户输入的数据
$username=$_REQUEST['username'];
$message=$_REQUEST['message'];
$sex=$_REQUEST['sex'];
$imgurl=$_REQUEST['imgurl'];
date_default_timezone_set('Asia/Shanghai');//设置时区
$date=date("Y-m-d h:i:s");
//写添加留言语句
$sql="insert into t_message(username,message,m_date,imgurl,sex) values('{$username}','{$message}','{$date}','{$imgurl}','{$sex}')";
$rs=$db->query($sql);
if ($rs==true)
{
    echo "<script language='javascript' type='text/javascript'>";
   // echo "alert('留言成功！');";
    echo "window.location.href='index.php'";
    echo "</script>";
} 
else
{
    echo "<script language='javascript' type='text/javascript'>";
    echo "alert('留言失败！');";
    echo "window.location.href='index.php'";
    echo "</script>";
}
$db->close();
       